<?php
namespace Qgs\Controller;

use Qgs\Controller\BaseController;
use Think\Controller;

class IdentityController extends BaseController
{
    public $obj;
    public $temp_obj;
    public $local_id;

    public function __construct()
    {
        parent::__construct();
        $this->obj = M('b2c_members');
        $this->_arr['title'] = '身份证信息审核';
        //$this->local_id = session('userInfo')['local_id'];
    }

    public function index()
    {
        $this->_arr['title_two'] = '身份证信息列表';
        $this->_arr['p'] = I('p', 1, 'intval');
        $this->_arr['select'] = I('select');
        $this->_arr['value'] = trim(I('value'));
        $this->_arr['view'] = I('view', 3, 'intval');
        $member_id = I('id',0);
        $view = [
            1 => ['identity_verifi' => '1'],
            2 => ['identity_verifi' => '2'],
            3 => ['identity_verifi' => '3'],
        ];
        if($this->_arr['view'] == 4){
            $where[] = ' 1=1 ';
        }else{
            $where[] = $view[$this->_arr['view']];
        }

        if ($member_id) {
            $where[] = ['member_id' => $member_id];
        }
        if($this->_arr['select'] && $this->_arr['value']){
            switch($this->_arr['select']){
                case 'mobile' :
                    $where[] = ['mobile' => $this->_arr['value']];
                    break;
                case 'identity_card_num' :
                    $where[] = ['identity_card_num' => $this->_arr['value']];
                    break;
                case 'identity_name' :
                    $where[] = ['identity_name' => ['like',$this->_arr['value']]];
                    break;
                case 'nickname' :
                    $where[] = ['nickname' => ['like',$this->_arr['value']]];
                    break;
            }
        }
        //dump($where);
        $data = $this->obj->where($where)->order('member_id desc')->page($this->_arr['p'] . ','.$this->page_num)->select();
        //echo M()->_sql();
        $count = $this->obj->where($where) ->count();// 查询满足要求的总记录数
        //dump($count);
        $Page = new \Think\Page($count, $this->page_num);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();// 分页显示输出
        //dump($show);
        $this->_arr['page'] = $show;// 赋值分页输出
        $this->_arr['list'] = $data;
        $this->_showDisplay();
    }

    /**
     * 审核
     */
    public function audit()
    {
        $id = I('id') ? I('id') : exit(json_encode(['msg' => '参数为空！', 'stat' => false]));
        if (!is_numeric($id)) exit(json_encode(['msg' => '无效参数！', 'stat' => false]));
        $status = I('status');
        $stat = $this->obj->where(['member_id' => $id])->data(['identity_verifi' => $status])->save();
        $stat === false ? $this->ajaxReturn(['stat' => false,'msg' => '失败']) : $this->ajaxReturn(['stat' => true,'msg' => '成功']);
    }


    public function __destruct()
    {
        unset($this->obj);
    }


}